package com.jhy.ws.strategy;

import cn.hutool.json.JSONUtil;
import com.jhy.core.enums.DeviceType;
import com.jhy.core.enums.UserType;
import com.jhy.ws.domain.bo.WsMsgRecordBo;
import com.jhy.ws.storage.WebSocketSessionStorage;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;

public class AppSendMsgTemplate extends SendMsgTemplate{

    public AppSendMsgTemplate(WsMsgRecordBo bo) {
        super(bo);
    }

    @Override
    public void sendMsg() throws IOException {
        WsMsgRecordBo bo = getBo();
        WebSocketSession webSocketSession = WebSocketSessionStorage.SESSION_MAP.get(UserType.SYS_USER.getUserType() + ":" + bo.getTargetId());
        if (webSocketSession != null) {
            webSocketSession.sendMessage(new TextMessage(JSONUtil.toJsonStr(bo)));
        }
    }
}
